package dyy.zc.campuspay.ui.activity;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;
import android.os.Message;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;



import dyy.zc.campuspay.R;
import dyy.zc.campuspay.base.BaseActivity;

import dyy.zc.campuspay.constant.Constants;

import dyy.zc.campuspay.utils.PayUtils;

public class PayStyleActivity extends BaseActivity implements View.OnClickListener {
    private RelativeLayout wx,ali;
    private TextView tvTitle;
    private TextView tvPayMoney;
    private PayUtils payUtils;
    public Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if (msg.what== Constants.ResultCode.SUCCESS){
                startActivity(MainActivity.class);
                finish();
            }
        }
    };
    @Override
    protected void findViewByIDS() {
        tvTitle = (TextView) findViewById(R.id.top_tv_title);
        tvPayMoney = (TextView) findViewById(R.id.tv_pay_money);
        wx = findViewsById(R.id.rl_wx);
        ali = findViewsById(R.id.rl_ali);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_style);
        initData();
        bind();
    }

    private void bind() {
        wx.setOnClickListener(this);
        ali.setOnClickListener(this);
    }

    private void initData() {
        tvTitle.setText("选择支付方式");
        Intent intent = getIntent();
        if (intent != null){
            tvPayMoney.setText("¥ "+intent.getStringExtra("price")+"");
            payUtils = new PayUtils(this,intent.getStringExtra("price"));
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_ali:
                payUtils.pay(true);
                break;
            case R.id.rl_wx:
                payUtils.pay(false);
                break;
        }
    }


}
